package com.yx.controller;

import com.yx.pojo.Emp;
import com.yx.pojo.LoginInfo;
import com.yx.pojo.Result;
import com.yx.service.EmpService;
import com.yx.utils.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
public class LoginController {
    @Autowired
    private EmpService empService;

    /**
     * 员工登录
     * @param emp
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("员工登录：{}",emp);
        LoginInfo loginInfo = empService.login(emp);
        if(loginInfo != null) {
            return ResultUtils.success(loginInfo);
        }
        //登录失败，返回错误信息
        return Result.error("用户名或密码错误");
    }

    /**
     * 退出登录
     */

    @PostMapping("user//logout")
    public Result logout(){
        empService.logout();
        return ResultUtils.success();
    }


}
